<!doctype html>
<html class="no-js">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="description" content="">
    <meta name="keywords" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>注册-{$siteInfo['title']}</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="stylesheet" href="/themes/amaze/assets/css/amazeui.min.css">
  </head>
  <body>  
    {include file="public/nav" /}    
    <form id="LoginForm" class="am-form" method="post">
      <fieldset>
        <legend>注册</legend>
        <div id="alert"></div>
        <div class="am-form-group">
          <label>邮箱</label>
          <input type="text" id="email" name="email" style="width:60%" placeholder="请输入邮箱">
          <button type="button" id="code-email" style="position: relative;left:60%;top:-38px;" class="am-btn am-btn-secondary">发送验证码</button>
        </div>
        <div class="am-form-group" id="code-div" style="position: relative;top:-30px;">
          <label>验证码</label>
          <input type="text" name="code" style="width:50%;" placeholder="输入验证码">
        </div>
        <div class="am-form-group"  style="position: relative;top:-30px;">
          <label>密码</label>
          <input type="password" name="pwd" class="" placeholder="输入密码">
        </div>
        <div class="am-form-group"  style="position: relative;top:-30px;">
          <label>重复密码</label>
          <input type="password" name="repwd" class="" placeholder="重复密码">
        </div>
        <p><button type="button" id="btn-register" class="am-btn am-btn-warning am-btn-block">立即注册</button></p>
        <p><a href="/home/index/login" class="am-btn am-btn-secondary am-btn-block">去登录</a></p>
      </fieldset>
    </form>    
    {include file="public/footer" /}     
    <script src="/themes/amaze/assets/js/amazeui.min.js"></script>
    <script>
      //提交注册
      $("#btn-register").click(function(){
        var data = $("#LoginForm").serialize();
        $.ajax({
          type:"post",
          url:"/home/index/register",
          data:data,
          success:function(e){
            switch(e.code)
                {                   
              case 204:
                $("#alert").html('<div class="am-alert am-alert-danger" data-am-alert>'+e.msg+'</div>');
                setTimeout(function(){
                  $("#alert").html("");
                },2000)     
                break;                    
              case 200:
                $("#alert").html('<div class="am-alert am-alert-success" data-am-alert>'+e.msg+'</div>');
                setTimeout(function(){
                  location.href="/home/index/login";
                },2000)     
                break;
            }
          }
        });      
      })
      //发送验证码
      $("#code-email").click(function(){
        var Email = $("#email").val();
        $.ajax({
          type:"post",
          url:"/home/index/regSendEmail",
          data:"email="+ Email,
          success:function(e){
            switch(e.code)
                {
              case 200:
                Timer("#code-email" );
                $("#code-email").attr("disabled","disabled");
                $("#alert").html('<div class="am-alert am-alert-success" data-am-alert>'+e.msg+'</div>');               
                setTimeout(function(){
                  $("#alert").html("");
                },2000)     
                break;
              case 204:
                $("#alert").html('<div class="am-alert am-alert-success" data-am-alert>'+e.msg+'</div>');
                setTimeout(function(){
                  $("#alert").html("");
                },2000)     
                break;          
            }
          }                     
        });
      });
      //倒计时器
      function Timer(obj) {
        $("#code-time").attr("disabled", "true")
        var time = 60;
        var timestap = "";
        var interval = setInterval(function() {
          if(timestap == "") {
            timestap = time - 1;
          } else {
            timestap = timestap - 1;
          }
          if(timestap == 0) {
            $(obj).removeAttr('disabled');
            $(obj).text("发送验证码");
            clear();
          } else {
            $(obj).text("获取验证(" + timestap + ")")
          }

        }, 1000);

        function clear() {
          clearInterval(interval)
        };
      }
    </script>
  </body>
</html>